const axios = require('axios');
const { getAccessToken } = require('./getWechatAccessToken');
const { createMenuUrl } = require('./urlList')

const createMenu = async () => {
    try {
        const access_token = await getAccessToken();
        console.log('打印***', access_token)
        const params = {
            "button": [
                {
                    "type": "view",
                    "name": "今日歌曲",
                    "url": "http://www.badidu.com/"
                },
                {
                    "name": "菜单",
                    "sub_button": [
                        {
                            "type": "view",
                            "name": "搜索",
                            "url": "http://www.soso.com/"
                        }]
                }]
        }
        console.log('打印***res', `${createMenuUrl}?access_token=${access_token}`)
        const res = await axios.post(`${createMenuUrl}?access_token=${access_token}`, params)
        console.log('打印***res', res.data)
        if (res.data.errcode === 0) {
            console.log('创建成功')
        } else {
            console.log('创建失败')
        }
    } catch (error) {
        console.log('创建失败')
    }
}


createMenu();